/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package parser;
import java.io.*;
import org.kxml.kdom.*;
import org.kxml.parser.*;
import conexion.Conexion;
/**
 *
 * @author Jaime Renato Castorela
 */
public class CargaXML {
    
     public static Element obtenRoot(String url){
        Element root = null;
        try{
            String xml = Conexion.peticionGET(url);
            ByteArrayInputStream xmlStream = new ByteArrayInputStream(xml.getBytes());
            InputStreamReader isr = new InputStreamReader(xmlStream);
            Document doc = new Document();
            XmlParser parser = new XmlParser(isr);
            doc.parse(parser);
            root = doc.getRootElement();
        }catch (IOException ioe) {
          System.err.println(ioe);
          ioe.printStackTrace();
        }
       
        return root;
     }

      public static Element obtenRoot(String url, String param, int valor){
        Element root = null;
        try{
            String xml = Conexion.peticionGETconParametro(url, param, valor);
            ByteArrayInputStream xmlStream = new ByteArrayInputStream(xml.getBytes());
            InputStreamReader isr = new InputStreamReader(xmlStream);
            Document doc = new Document();
            XmlParser parser = new XmlParser(isr);
            doc.parse(parser);
            root = doc.getRootElement();
        }catch (IOException ioe) {
          System.err.println(ioe);
          ioe.printStackTrace();
        }

        return root;
     }

}
